package com.course.business.config;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;

import javax.annotation.PostConstruct;

/*
@Configuration
@EnableElasticsearchRepositories(basePackages = "com.test",includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchRepository.class))
public class ElasticsearchConfiguration {
 */
@SpringBootApplication
@EnableDiscoveryClient
@ComponentScan(value = {"com.course.server"})
@ComponentScan("com.course")

@MapperScan({"com.course.server.mapper.generator","com.course.server.mapper.my"})
@EnableElasticsearchRepositories(basePackages = "com.course.server.mapper.elasticsearch")
//@ComponentScan(basePackages = {"org.test.elasticsearch.configs", "org.test.webapp"})
//@MapperScan({"com.course.server.mapper.categoryMapper","com.course.server.mapperChapterMapper"})
//@ComponentScan("com.course")

//@EnableElasticsearchRepositories(basePackages = "com.course.server.mapper.my.elasticsearch")

public class BusinessApplication {

	private static final Logger LOG = LoggerFactory.getLogger(BusinessApplication.class);

	public static void main(String[] args) {
		System.setProperty("es.set.netty.runtime.available.processors", "false");

		SpringApplication app = new SpringApplication(BusinessApplication.class);
		Environment env = app.run(args).getEnvironment();
		LOG.info("启动成功！！");
		LOG.info("Business地址: \thttp://127.0.0.1:{}", env.getProperty("server.port"));
	}

	@PostConstruct
	public void init() {
		// 解决netty启动冲突问题
		// see Netty4Utils.setAvailableProcessors()
		System.setProperty("es.set.netty.runtime.available.processors", "false");
	}


}
